/** 
 * @fileOverview 本插件用于给jQuery方法添加回调函数，可在类方法或实例方法添加任何自定义的回调函数而不影响原方法的行为 
 * @dependency jQuery1.7+ 
 * @author huhai 
 * @since 2013-01-21 
 */  
(function($){  
    $._callbacks = {};  
    $._callbacks_ = {};  
    $._alias = {};  
    $._alias_ = {};  
  
    $.extend({  
  
        /** 
         * @decription 给方法添加回调函数 
         * @param funcName : string 需要添加回调的函数名称 
         * @param callback : function 回调函数（如需移除，不要使用匿名方法） 
         * @param static : boolean 是否是类方法，默认为false 
         */  
        addCallback : function(funcName, callback, static){  
            if("string" === typeof(funcName) && $.isFunction(callback)){  
                if(static === true){  
                    if($[funcName] && $.isFunction($[funcName])){  
                        if(!this._callbacks[funcName]){  
                            this._callbacks[funcName] = $.Callbacks();        
                        }  
                        this._callbacks[funcName].add(callback);  
                        if(!$._alias[funcName]){  
                            $._alias[funcName] = $[funcName];//寄存原来的类方法  
                              
                            $[funcName] = function(){//代理类方法；  
                            var result = $._alias[funcName].apply(this, arguments);  
                            $._callbacks[funcName].fireWith(this, arguments);  
                            return result;  
                            };  
                        }                         
                    }  
                }else{  
                    if($.fn[funcName] && $.isFunction($.fn[funcName])){  
                        if(!this._callbacks_[funcName]){  
                            this._callbacks_[funcName] = $.Callbacks();       
                        }  
                        this._callbacks_[funcName].add(callback);  
                        if(!$._alias_[funcName]){  
                            $._alias_[funcName] = $.fn[funcName];//寄存原来的实例方法  
                            $.fn[funcName] = function(){//代理实例方法；  
                                var result = $._alias_[funcName].apply(this, arguments);  
                                $._callbacks_[funcName].fireWith(this, arguments);  
                                return result;  
                            };  
                        }  
                    }  
                }  
            }  
        },  
  
        /** 
         * @decription 移除给方法添加的回调函数 
         * @param funcName : string 已添加回调的函数名称 
         * @param callback : function 回调函数 
         * @param static : boolean 是否是类方法，默认为false 
         */  
        removeCallback: function(funcName, callback, static){  
            if("string" === typeof(funcName) && $.isFunction(callback)){  
                if(static === true){  
                    if($[funcName] && $.isFunction($[funcName])){  
                        if(this._callbacks[funcName]){  
                            this._callbacks.remove(callback);  
                        }  
                    }  
                }else{  
                    if($.fn[funcName] && $.isFunction($.fn[funcName])){  
                        if(this._callbacks_[funcName]){  
                            this._callbacks_.remove(callback);  
                        }  
                    }  
                }  
            }  
        }  
    });  
})(jQuery);  

$(document).ready(function () {
	 $.addCallback("lazyload", function(){ 
	 var loading = $(this).parent().find("img.loading");

	if(loading)
	{
		loading.hide();
	}
	 });
	//hungry-func
	if( jQuery.isFunction(jQuery.fn.lazyload) ){  
	$("img.lazy").each(function(){
		$(this).show().lazyload({ event:'load'});
		
	});
	
	/*var loading=$("img.lazy").parent().find("img.loading");
	console.log(loading);
	if(loading)
	{
		loading.hide();
	}*/
	}

	
	$('.lang-switch').click(function() {
		if($.cookie('home_lang')==1)
		{
			$.cookie('home_lang',2,{'max-age':7200,path:'/'})
		}
		else
		{
			$.cookie('home_lang',1,{'max-age':7200,path:'/'})
		}
		window.history.go(0);
	});
	
	//product-cover
	$('.product-col').hover(function() {
		$(this).find('.product-cover').stop().fadeIn();
	},
	function() {
		$(this).find('.product-cover').stop().fadeOut();
	});
	
	$('.map_detail').click(function() {
		$(' #detail_title').html($(this).html());
		var id=$(this).attr('data-area');
		$.post('/article/ajax_content.html',{id:id},function(result){
			if(result.error==0)
			{
				$(' .area_content').html(result.content);
				
			}
			},'json')
	});
	$('.weixin-link').hover(function() {
		
		$('#qqcode').stop().show()
	},function() {
		
		$('#qqcode').stop().hide()
	});
	
	
	$('li.sub').click(function (e) {
		$clickItem = $(e.target);
		if ($clickItem.attr('href') === '#') {
			e.preventDefault();
			$(this)
				.siblings()
				.find('ul.sub-menu')
				.stop()
				.slideUp('fast');
			$(this)
				.find('ul.sub-menu')
				.stop()
				.slideToggle('fast');
		}
	});

	$('div.show-block').hover(function () {
		$(this)
		.find('div.show-block-mask').stop().fadeToggle()
		.end().find('div.show-block-extra').stop().slideToggle();
	});

	function fixFullPageSize() {
		var windowHeight = $(window).height();
		$('div.full-page').height(windowHeight - 80);
	}
	fixFullPageSize();
	$(window).resize(fixFullPageSize);

	// event page
	var firstYear = $('[data-year]').first().data('year');
	var initLeft = getLeft(firstYear);

	function getLeft (year) {
		return (year - 2000) * 100 + 100;
	}
	
	var $eventImgs = $('div.event-imgs');
	var $eventPointer = $('div.event-pointer');
	var $rulerImg = $('div.ruler img');
	// initail event img position
	var rule_point = $('.rule_point');
	var point_left=parseInt()+parseInt(initLeft);
	
	$eventImgs.animate({
		'left': initLeft + 'px'
	}, 1000, 'easeOutQuart', function () {
		$('[data-year]').first().addClass('active');
	});
	$eventPointer.delay(200).animate({
		'left': initLeft - 15 + 'px'
	}, 1000, 'easeOutQuart');

	$eventImgs.children().click(function () {
		var $this = $(this);
		var clickYear = $this.data('year');
		var clickLeft = $this.offset().left;
		var relativeLeft = clickLeft - $eventImgs.offset().left;
		
		$('[data-year].active').removeClass('active');
		$this.addClass('active');

		$eventImgs.stop().animate({
			'left': initLeft - relativeLeft + 'px'
		}, 1000, 'easeOutQuart');

		var rulerLeft =  (firstYear - clickYear) * 100;
		
		rule_point.each(function(index, element) {
			
			var pointLeft=parseInt($(this).attr('data-left'))+parseInt(rulerLeft);
			console.log(pointLeft);
            $(this).stop().animate({
			'left': pointLeft+'px', 
		}, 1000, 'easeOutQuart');
        });
		
		
		$rulerImg.stop().animate({
			'left': rulerLeft, 
		}, 1000, 'easeOutQuart');
	});
	

	// center design-total
/*	function centerDesignTotal () {
		var totalLen = $('div.design-total').width();
		var realLen = $('div.design-main').width() + 45 +
					  $('div.show-block-sm').width() +
					  $('div.design-title').width();
		$('div.design-total').css('margin-left', (totalLen - realLen + 15) / 2);
	}
	centerDesignTotal();
	$(window).resize(centerDesignTotal);*/

	var $fashionCarousel = $('#fashion-carousel');
	var $fashionPoint = $('ul.fashion-point');
	$('div.fashion-left').click(function () {
		$fashionCarousel.carousel('prev');
	});
	$('div.fashion-right').click(function () {
		$fashionCarousel.carousel('next');
	});
	$fashionCarousel.on('slid.bs.carousel', function () {
		var activeIndex = $(this).find('div.active').index();
		$fashionPoint.find('.active').removeClass('active')
		.end().find('li').eq(activeIndex).addClass('active');
	});
	$fashionPoint.on('click', 'li', function () {
		// carousel is using css animation
		var $this = $(this);
		var clickIndex = $this.index();
		$fashionCarousel.carousel(clickIndex);
	});
	$('.hy_reg').click(function(){
		$('.ajax_reg').show();
		$('.ajax_login').hide();
		
	});
	$('.hy_only_user').click(function(){
		$('.ajax_login').show();
		
	});
	$('.login-close').click(function(){
		$('.ajax_login').hide();
	});
});